#!/usr/bin/python

#import pynotify
#import os
import os
from pyinotify import WatchManager, Notifier, ThreadedNotifier, IN_DELETE, IN_CREATE, IN_CLOSE_WRITE, ProcessEvent


mask = IN_CLOSE_WRITE | IN_DELETE | IN_CREATE  # watched events

class PTmp(ProcessEvent):
    def process_IN_CREATE(self, event):
        print "Create: %s" %  os.path.join(event.path, event.name)

    def process_IN_DELETE(self, event):
        print "Remove: %s" %  os.path.join(event.path, event.name)

    def process_IN_CLOSE_WRITE(self, event):
        print "Close write: %s" %  os.path.join(event.path, event.name)
        os.system('php /var/www/html/index.php Notify')


# Instanciate a new WatchManager (will be used to store watches).
wm = WatchManager()
# Associate this WatchManager with a Notifier (will be used to report and
# process events).
notifier = Notifier(wm, PTmp())
   
# Add a new watch on /tmp for ALL_EVENTS.
wm.add_watch('/var/www/html/notify', mask)
# Loop forever and handle events.
notifier.loop()


